<?php
class MonedasController extends AppController {
	var $name = 'Monedas';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		
		if($this->JQGridPaginate->isGrid){
			$fields = array('Moneda.id','Moneda.simbolo','Moneda.nombre','"Moneda"."created"::date AS "Moneda__created"','"Estado"."descripcion" AS "Moneda__estado"');
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Moneda");
			$this->autoRender = false;
		}elseif($this->RequestHandler->isPost()){	
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
				$this->Moneda->create();				 
			}elseif ($oper == "edit"){
				$this->data['Moneda']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Moneda']['id'] = $this->params['form']['id'];
				$this->data['Moneda']['estado_id'] = 2;				
			}
			
			@$this->Moneda->save($this->data['Moneda']);
			echo json_encode($this->Moneda->visualizarError($this->Moneda->validationErrors));
			$this->autoRender = false;			
		}		
	}
	
	function listamonedas(){
		$this->layout="ajax";
		$listaMonedas = $this->Moneda->find('list',array('fields'=>array('Moneda.id','Moneda.nombre'),
															'order'=>'Moneda.nombre'));
		echo json_encode($listaMonedas);
		$this->autoRender = false;
	}	
}